﻿@{
    if(!Check.CheckLogin())
    {
        Response.Write("未登录!");
        Response.End();
    }
    
    string html = Request["html"];
    string name = Request["name"];
    string att = Request["att"];
    string id = Request["id"];
    string type = Request["type"];
    string subtable = Request["subtable"];
    if(name.IsNullOrEmpty())
    {
        Response.Write("表单名称不能为空!");
        Response.End();
    }

    Guid formID;
    if(!id.IsGuid(out formID))
    {
        Response.Write("表单ID无效!");
        Response.End();
    }

    Business.Platform.WorkFlowForm WFF = new Business.Platform.WorkFlowForm();
    Data.Model.WorkFlowForm wff = WFF.Get(formID);
    bool isAdd = false;
    string oldXML = string.Empty;
    if(wff == null)
    {
        wff = new Data.Model.WorkFlowForm();
        wff.ID = formID;
        wff.Type = type.ToGuid();
        wff.CreateUserID = Business.Platform.Users.CurrentUserID;
        wff.CreateUserName = Business.Platform.Users.CurrentUserName;
        wff.CreateTime = Utility.DateTimeNew.Now;
        wff.Status = 0;
        isAdd = true;
    }
    else
    {
        oldXML = wff.Serialize();
    }

    wff.Attribute = att;
    wff.Html = html;
    wff.LastModifyTime = Utility.DateTimeNew.Now;
    wff.Name = name;
    wff.SubTableJson = subtable;
   
    if(isAdd)
    {
        WFF.Add(wff);
        Business.Platform.Log.Add("添加了流程表单", wff.Serialize(), Business.Platform.Log.Types.流程相关);
    }
    else
    {
        WFF.Update(wff);
        Business.Platform.Log.Add("修改了流程表单", "修改前：" + oldXML + "修改后：" + wff.Serialize(), Business.Platform.Log.Types.流程相关);
    }
    Response.Write("保存成功!");
    Response.End();
}